import 'package:sow_app_core/src/error/exception.dart';
import 'package:sow_app_core/src/usecase/subscribe_usecase.dart';
import 'package:test/test.dart';

import 'package:sow_app_mock/sow_app_mock.dart';

void main() {
  group('subscribe usecase test group', () {
    const novelId = "1";
    final MockNovelRepository novelRepository = MockNovelRepository();
    test(
      "should return true when call SubscribeNovelUseCase() with  novelId", // todo this may be a backend problem
      () async {
        // arrange
        final usecase = SubscribeNovelUseCase(novelRepository);
        // act
        await usecase(novelId);

        // assert
      },
    );

    test(
      "should return false when call SubscribeNovelUseCase() with same novelId", // todo this may be a backend problem
      () async {
        // arrange
        final usecase = SubscribeNovelUseCase(novelRepository);
        // act
        try {
          await usecase(novelId);

          // assert
        } on ServerException catch (e) {
          expect(e.msg, "请勿重复订阅");
        }
      },
    );
    test(
      "should return true when call UnsubscribeNovelUseCase() with same novelId", // todo this may be a backend problem
      () async {
        // arrange
        final usecase = UnsubscribeNovelUseCase(novelRepository);
        // act
        await usecase(novelId);

        // assert
      },
    );
    test(
      "should return false when call UnsubscribeNovelUseCase() with same novelId", // todo this may be a backend problem
      () async {
        // arrange
        final usecase = UnsubscribeNovelUseCase(novelRepository);
        // act
        try {
          await usecase(novelId);
          // assert
        } on ServerException catch (e) {
          expect(e.msg, "操作失败");
        }
      },
    );
  });
}
